package com.ruoyi.web.controller.report;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.report.domain.TRptOrder;
import com.ruoyi.report.service.ITRptOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报修单Controller
 * 
 * @author ruoyi
 * @date 2025-09-24
 */
@RestController
@RequestMapping("/system/report/order")
public class TRptOrderController extends BaseController
{
    @Autowired
    private ITRptOrderService tRptOrderService;

    /**
     * 查询报修单列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(TRptOrder tRptOrder)
    {
        startPage();
        List<TRptOrder> list = tRptOrderService.selectTRptOrderList(tRptOrder);
        return getDataTable(list);
    }

    /**
     * 导出报修单列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:export')")
    @Log(title = "报修单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TRptOrder tRptOrder)
    {
        List<TRptOrder> list = tRptOrderService.selectTRptOrderList(tRptOrder);
        ExcelUtil<TRptOrder> util = new ExcelUtil<TRptOrder>(TRptOrder.class);
        util.exportExcel(response, list, "报修单数据");
    }

    /**
     * 获取报修单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:order:query')")
    @GetMapping(value = "/{reportNo}")
    public AjaxResult getInfo(@PathVariable("reportNo") String reportNo)
    {
        return success(tRptOrderService.selectTRptOrderByReportNo(reportNo));
    }

    /**
     * 新增报修单
     */
    @PreAuthorize("@ss.hasPermi('system:order:add')")
    @Log(title = "报修单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TRptOrder tRptOrder)
    {
        return toAjax(tRptOrderService.insertTRptOrder(tRptOrder));
    }

    /**
     * 修改报修单
     */
    @PreAuthorize("@ss.hasPermi('system:order:edit')")
    @Log(title = "报修单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TRptOrder tRptOrder)
    {
        return toAjax(tRptOrderService.updateTRptOrder(tRptOrder));
    }

    /**
     * 删除报修单
     */
    @PreAuthorize("@ss.hasPermi('system:order:remove')")
    @Log(title = "报修单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reportNos}")
    public AjaxResult remove(@PathVariable String[] reportNos)
    {
        return toAjax(tRptOrderService.deleteTRptOrderByReportNos(reportNos));
    }
}